<template>
  <el-upload
    class="upload-demo"
    drag
    :action="url"
    multiple
    :on-success="successHandler"
    :on-error="errorHandler"
  >
    <el-icon class="el-icon--upload"><upload-filled /></el-icon>
    <div class="el-upload__text">拖拽至此 或 <em>点击上传</em></div>
  </el-upload>
</template>

<script setup>
import host from "@/utils/host";
import { ElMessage } from "element-plus";
import { UploadFilled } from "@element-plus/icons-vue";
import { defineEmits, computed } from "vue";
import store from "@/store";

const emit = defineEmits(["child-click"]);

const url = computed(() => {
  return `http://${host}/tran/file/file?path=${store.getters.getBackTop}`;
});

const successHandler = (msg) => {
  ElMessage({
    message: `${msg.data}`,
    type: "success",
  });
  //通知fileList 刷新文件列表
  emit("messageToParent", null);
};

const errorHandler = (msg) => {
  ElMessage.error(`${msg}`);
};
</script>
